package com.lecode.ThreadPrint;

/**
 * Created by Administrator on 2022/2/7.
 */
public class ThreadPrint implements Runnable{

    //锁
    private static Object object = new Object();
    private int total = 100;   //总数
    private static volatile int curNum = 0;  //当前数字

    private int flag;

    public ThreadPrint(int flag) {
        this.flag = flag;
    }

    public void run() {
        synchronized (object) {
            while (true && curNum <= total) {
                if ((curNum % total) != flag) {
                    System.out.println("=======" + curNum);
                    curNum++;
                    object.notifyAll();
                } else {
                    try {
                        object.wait();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
